/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Persistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author kenneth
 */
public class DatabaseConnection {
    private final String url = "jdbc:mysql://kennero87.eightyseven.axc.nl:3306/";
    private final String dbName = "kennero87_datacom";
    private final String driver = "com.mysql.jdbc.Driver";
    private final String userName = "kennero87_user";
    private final String password = "datacomproject";
    private Connection conn;
    
    public DatabaseConnection() {
          
    }
    
    public void openConnection() {
        try {
          Class.forName(driver).newInstance();
          conn = DriverManager.getConnection(url+dbName,userName,password);
           
          
        } catch (Exception e) {
          e.printStackTrace();
        }
    }
    
    public ResultSet executeQuery(String query) throws SQLException {
        Statement stat = conn.createStatement();
        return stat.executeQuery(query);
    }
    
    public void closeConnection() {
        try {
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(DatabaseConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
